from turnited._config import *

import wsgiref.handlers
import os

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp import template

#from django.formas import newforms as forms
from google.appengine.ext.db import djangoforms
from google.appengine.api import datastore_errors
from django import newforms as forms

class TurnitedPageBase(webapp.RequestHandler):
    def _commonRender(self, fn_template, template_values):
        user = users.get_current_user()
        if users.get_current_user():
            url = users.create_logout_url(self.request.uri)
            url_linktext = "Logout"
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = "Logout"
        template_values.update({
            'admin' : BASE_REQ_ADMIN,
            'static' : BASE_REQ + "/static",
            'nickname': user.nickname()  if user  else "",
            'email': user.email()  if user  else "",
            'is_admin': users.is_current_user_admin(),
            'url': url,
            'url_linktext': url_linktext,
            })
        self.response.out.write(
            template.render(fn_template, template_values)
            )


